package com.zwz.service.impl;
import com.zwz.entity.CompanyOperationStatus;
import com.zwz.entity.EnterpriseInfo;
import com.zwz.mapper.CompanyOperationStatusMapper;
import com.zwz.service.CompanyOperationStatusService;
import com.zwz.voObject.Bid;
import com.zwz.voObject.CompanyStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class CompanyOperationStatusServiceImpl implements CompanyOperationStatusService {

    @Autowired
    private CompanyOperationStatusMapper mapper;

    @Override
    public void create(CompanyOperationStatus record) {
      //  validateFinancingData(record); //todo 以后待校验
        // 1. 创建主表记录
        // 主表操作
        EnterpriseInfo enterpriseInfo=new EnterpriseInfo();
        enterpriseInfo.setId(Long.valueOf(record.getEnterpriseId()));

        record.setEnterpriseId(Math.toIntExact(enterpriseInfo.getId()));
        mapper.insert(record);
    }

    @Override
    public void update(CompanyOperationStatus record) {
        validateFinancingData(record);
        mapper.update(record);
    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public CompanyOperationStatus getById(Integer id) {
        return null;
    }

    @Override
    public CompanyOperationStatus selectByHighTech(Boolean isHighTech) {
        return null;
    }

    @Override
    public List<CompanyStatus> getInfo(String id) {
        return mapper.getCompanyInfo(id);
    }

    @Override
    public List<Bid> getBidInfo(String id) {
        return mapper.getBidInfo(id);
    }

    private void validateFinancingData(CompanyOperationStatus record) {
        if (record.getFinancingCount() > 0 && record.getCurrentFinancingRound() == null) {
            throw new IllegalArgumentException("存在融资记录必须填写融资轮次");
        }
    }



//    @Override
//    public List<CompanyOperationStatus> getByFinancingRound(String round) {
//        return mapper.selectByFinancingRound(round);
//    }
}